import {Login} from "./login/login.js" // 登录页
import {Layout} from "./layout/layout.js" //布局
// 路由
const routes = [
    {path:'/',redirect:'/login'},
    {path: '/login', component: Login,},
    {path: '/layout', component: Layout},
]
const router = new VueRouter({
    routes
})
const app = new Vue({
    router
}).$mount('#root')
// 拦截器
router.beforeEach((to, from, next) => {
    const user = JSON.parse(window.localStorage.getItem('user')) /* 获取用户登录数据*/
    /* 判断用户是否登录，是否在登录页面 */
    if (to.path !== '/login' ) {
        /* 判断用户是否登录，如果登录就正常访问，负责就返回登录页面 */
        if (user) {
            next()
        } else {
            next('/')
        }
    } else {
        next()
    }
})